package com.lihepeng.leecode.frequency.tree;

import java.util.ArrayList;

/**
 * 前序遍历
 */
public class Solution23 {
    ArrayList<Integer> arrayList = new ArrayList<>();
    public int[] preorderTraversal (TreeNode root) {

        int[] result = new int[arrayList.size()];
        if (root == null) {
            return result;
        }
        preorderTraversalInn(root);
        for (int i=0;i<arrayList.size();i++) {
            result[i] = arrayList.get(i);
        }
        return result;
    }
    public void preorderTraversalInn (TreeNode root){
        if (root ==null){
            return;
        }
        arrayList.add(root.val);
        preorderTraversal(root.left);
        preorderTraversal(root.right);
    }
}
